package com.soryin.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSONObject;
import com.soryin.entity.Soryin;
import com.soryin.entity.User;
import com.soryin.util.HttpUtil;

/**
 * 用于 处理、显示 Header
 * @author Hello_海生
 * @date 2014年4月23日
 */
@WebServlet("/header")
public class HeaderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public HeaderServlet() {
        super();
        System.out.println("HeaderServlet 初始化。");
    }
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	//编写处理方法
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");	

		String sId=request.getParameter("sId");		//获取缩影信息ID
		String uId=request.getParameter("uId");		//获取 用户ID
		//获取缩影信息
		JSONObject jsobj = HttpUtil.getJsonp("http://db.soryin.com/soryin/show?key=Soryin&id="+sId);
		Soryin soryin = jsobj.getJSONObject("result").getObject("soryin", Soryin.class);
		//获取个人信息
		jsobj = HttpUtil.getJsonp("http://db.soryin.com/user/show?key=Soryin&id="+uId);
		User user = jsobj.getJSONObject("result").getObject("user", User.class);
		
		
		HttpSession session=request.getSession();
		session.setAttribute("soryin", soryin);		//缩影信息
		session.setAttribute("user", user);		//用户Id
		session.setAttribute("sType", "展会");		//缩影信息类型
		session.setAttribute("sDate", "5");		//缩影信息已发布多少天
		session.setAttribute("sRelation", "2%");		//缩影信息，相关
		session.setAttribute("sUserCount", "4");		//缩影信息，关注人数
		response.sendRedirect("header.jsp");
		
		
	}

}
